#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<vector<int>> a(6000);
vector<int> in(6000);
vector<int> out(6000);
vector<int> ans(6000);
int main() {
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        a[x].push_back(y);
        out[x]++;
        in[y]++;
    }
    queue<int> q;
    for(int i = 1; i <= n; i++) {
        if(in[i] == 0) {
            ans[i] = 1;
            q.push(i);
        }
    }
    while(!q.empty()) {
        int temp = q.front();
        q.pop();
        for(auto& s : a[temp]) {
            ans[s] = (ans[s] + ans[temp]) % 80112002;
            in[s]--;
            if(in[s] == 0) {
                q.push(s);
            }
        }
    }
    int ret = 0;
    for(int i = 1; i <= n; i++) {
        if(out[i] == 0) {
            ret = (ret + ans[i]) % 80112002;
        }
    }
    cout << ret << endl;

    return 0;
}